package com.ruoyi.web.controller.user;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.user.domain.Health;
import com.ruoyi.user.service.IHealthService;

/**
 * 心率/血压/血氧 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-12-23
 */
@Controller
@RequestMapping("/module/health")
public class HealthController extends BaseController
{
    private String prefix = "module/health";
	
	@Autowired
	private IHealthService healthService;
	
	@RequiresPermissions("module:health:view")
	@GetMapping()
	public String health()
	{
	    return prefix + "/health";
	}
	
	/**
	 * 查询心率/血压/血氧列表
	 */
	@RequiresPermissions("module:health:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Health health)
	{
		startPage();
        List<Health> list = healthService.selectHealthList(health);
		return getDataTable(list);
	}
	
	/**
	 * 新增心率/血压/血氧
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存心率/血压/血氧
	 */
	@RequiresPermissions("module:health:add")
	@Log(title = "心率/血压/血氧", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Health health)
	{		
		return toAjax(healthService.insertHealth(health));
	}

	/**
	 * 修改心率/血压/血氧
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Health health = healthService.selectHealthById(id);
		mmap.put("health", health);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存心率/血压/血氧
	 */
	@RequiresPermissions("module:health:edit")
	@Log(title = "心率/血压/血氧", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Health health)
	{		
		return toAjax(healthService.updateHealth(health));
	}
	
	/**
	 * 删除心率/血压/血氧
	 */
	@RequiresPermissions("module:health:remove")
	@Log(title = "心率/血压/血氧", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(healthService.deleteHealthByIds(ids));
	}
	
}
